<style>
body {
    overflow-x: hidden;
    background-color: #f8f8f8;
}
p{margin:0;}
.page-head, .question-head {
    top: 0px;
    width: 100%;
    z-index: 1;
    font-size: 1.2em;
    padding: 0.7em 0;
    border-bottom: 1px solid #ddd;
    font-weight: bold;
    top: 0px;
}

.baoming-div {
    color: #3a87ad;
    text-align: center;
    color: #009def;
    vertical-align: middle;
    cursor:pointer;
}
.baomingd {
    color: red;
    cursor: default;
}
.baomingNum {
    font-size: 32px;
    font-weight: 100;
    clear: both;
    margin: 0px;
    line-height: 40px;white-space: pre;
}
.clickToVote {
	white-space: pre;
    font-size: 10px;
    margin: 0px;
    height: 100%;
}
#maincontent{background-color: transparent;margin-bottom: 20px;}
th,td{background-color: #fff;padding:5px 5px;}
label{margin-bottom: 0px;}
.bs-navbar-collapse{display: none;}
.col-md-3{width:100%;}
[data-toggle="buttons"] > .btn input[type="radio"], [data-toggle="buttons"] > .btn-group > .btn input[type="radio"], [data-toggle="buttons"] > .btn input[type="checkbox"], [data-toggle="buttons"] > .btn-group > .btn input[type="checkbox"] {
    position: relative;}
#pickup-addresses label{display:block;}
.cart-concern-btm-fixed {
    display: table;
    position: fixed;
    left: 0;
    bottom: 0;
    z-index: 10;
    text-align: center;
    width: 100%;
    height: 50px;
    overflow: hidden;
}
#baoming-list-area{margin:10px auto 20px;}
.table{margin-bottom: 0;}
.order-item{display: flex;background: #FFF;margin-bottom: 20px;    padding: 5px;}
.user-avatar{width: 45px;margin-top: -25px;}.user-avatar img{border-radius: 100%;}
.user-goods{flex:1;padding-left: 10px;}
.concern-cart {
    width: 37.5%;float: left; height: 50px;overflow: hidden;background-color: rgba(255,255,255,.9); position: relative;
}
.concern-cart a {
    width: 33.33%;color:#232326;font-size: 12px;display: inline-block;line-height: 50px;
}
.concern-cart .fa{
	width: 23px;
    height: 16px;
    display: block;
    margin: 0 auto;
    background-color: #fff;
    margin-top: 10px;
    margin-bottom: 4px;font-size: 14px;
}
.concern-cart a span {
    display: block;
    line-height: 9px;
    height: 15px;
    text-align: center;
}
.action-list {
    float: left;width: 62.5%;
    height: 100%;
    overflow: hidden;
}
.directorder{width:100%;background-color: #f23030;display: inline-block;color: #fff;line-height: 50px; font-size: 15px;}
.directorder:hover,.directorder:focus{color:#FFF;}
</style>
<script>
window.onerror = function(errorMessage, scriptURI, lineNumber,columnNumber,errorObj) { 
	var str = '';
    str += "错误信息：" + errorMessage; 
    str += "出错文件：" + scriptURI; 
    str += "出错行号：" + lineNumber; 
    str += "出错列号：" + columnNumber; 
    str += "错误详情：" + errorObj; 
    document.write(str);
} 
</script>


{{if $isWeixin}}
<script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script>
<script>

wx.config({
    debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来，若要查看传入的参数，可以在pc端打开，参数信息会通过log打出，仅在pc端时才会打印。
    appId: "{{$signPackage['appId']}}", // 必填，公众号的唯一标识
    timestamp: {{$signPackage['timestamp']}}, // 必填，生成签名的时间戳
    nonceStr: "{{$signPackage['nonceStr']}}", // 必填，生成签名的随机串
    signature: "{{$signPackage['signature']}}",// 必填，签名，见附录1
    jsApiList: ['onMenuShareTimeline','onMenuShareAppMessage','onMenuShareQQ','onMenuShareWeibo','onMenuShareQZone'] // 必填，需要使用的JS接口列表，所有JS接口列表见附录2
});

window.share_config = {
     "share": {
        "imgUrl": "{{$WxActivity['WxActivity']['coverimg']}}",//分享图，默认当相对路径处理，所以使用绝对路径的的话，“http://”协议前缀必须在。
        "desc" : "{{$WxActivity['WxActivity']['summary']?str_replace(array("\r","\n"),'',$WxActivity['WxActivity']['summary']):$pageTitle.'-'.$site[title]}}",//摘要,如果分享到朋友圈的话，不显示摘要。摘要不能有折行
        "title" : '{{$pageTitle}}',//分享卡片标题
        "link": window.location.href,//分享出去后的链接，这里可以将链接设置为另一个页面。
        "success":function(){//分享成功后的回调函数
        },
        'cancel': function () { 
            // 用户取消分享后执行的回调函数
        }
    }
};  

wx.ready(function(){
	wx.onMenuShareAppMessage(share_config.share);//分享给好友
    wx.onMenuShareTimeline(share_config.share);//分享到朋友圈
    wx.onMenuShareQQ(share_config.share);//分享给手机QQ
    wx.onMenuShareWeibo(share_config.share); //分享到微博
    wx.onMenuShareQZone(share_config.share); //分享到QQ空间
});

</script>

{{/if}}

<div class="row">
    	<div class="col-xs-12">
      		<div class="wx-cover-item noborder">
      			{{if $WxActivity['WxActivity']['coverimg']}}
	       			{{$this->Html->image($WxActivity['WxActivity']['coverimg'])}}
	       		{{/if}}
				<h2 class="question-head">{{$WxActivity['WxActivity']['name']}}</h2>
			</div>

			{{if $WxActivity['WxActivity']['creator']==$current_user_id}}
				<p class="mb10"><a class="btn btn-primary btn-sm" href="/wx_activities/edit/{{$id}}"><i class="fa fa-edit"></i> 编辑</a>  &nbsp;

					<a class="btn btn-primary btn-sm" onclick="return publishController.open_dialog(this.href,{title:'选择群并发送消息'});" href="/bots/choosegroup?model=WxActivity&data_id={{$id}}"><i class="fa fa-bell"></i> 发布提醒</a> &nbsp;

					<a class="btn btn-primary btn-sm" href="/orders/mine?model=WxActivity&data_id={{$id}}&type=shop"><i class="fa fa-cny"></i> 查看活动订单</a></p>

				<p>
					<a class="btn btn-primary btn-sm" target="_blank" href="/wx_activities/copy/{{$id}}"><i class="fa fa-copy"></i> 复制活动</a>

					{{if $WxActivity['WxActivity']['status'] == 1}}
					<a class="btn btn-primary btn-sm" onclick="return ajaxAction(this.href);" href="/wx_activities/setstatus/{{$id}}/0"><i class="fa fa-power-off"></i> 结束活动</a>
					{{else}}
					<a class="btn btn-primary btn-sm" onclick="return ajaxAction(this.href);" href="/wx_activities/setstatus/{{$id}}/1"><i class="fa fa-plane"></i> 重新开始活动</a>
					{{/if}}
				</p>
			{{elseif in_array($current_user_id,$super_uids)}}
				<p class="mb10"><a class="btn btn-primary btn-sm" href="/orders/mine?model=WxActivity&data_id={{$id}}&type=shop&shop_id={{$WxActivity['WxActivity']['creator']}}"><i class="fa fa-cny"></i> 查看活动订单</a></p>
			{{/if}}

       		<div style="border:1px solid #eee;padding:5px;margin:10px 0;background: #FFF;">
       			{{if $WxActivity['WxActivity']['content']}}
					{{$WxActivity['WxActivity']['content']}}
				{{elseif $WxActivity['WxActivity']['summary']}}
					<p>{{nl2br($WxActivity['WxActivity']['summary'])}}</p>
				{{/if}}
			</div>
<style>
.baoming-item {height:270px;text-align:center;min-width:140px;}
.baoming-item img{max-height:160px;}
.baoming-item-img {height:160px;display:table-cell;vertical-align: middle;text-align:center; width: 250px;max-width: 100%;}
.baoming-item h4{height:32px;}
#part_consignee .consignee-item:nth-child(n+2) {
	display: none;
}
.modal-open .modal {overflow-x: hidden; overflow-y: auto;}
</style>			

		<div id="baoming-list-area">
			<table id="baoming-items" style="width:100%;box-shadow: 0 2px 5px #ddd;margin-bottom:10px;"><tbody>
				<portlet cache="no" limit="200" portlet="body" model="Baoming" list_tpl="inner" conditions="model=WxActivity&data_id=$id">
					<tr>
						<td width="68%">
							<p style="font-size: 16px;"><strong>{{$item['name']}}</strong></p>
							{{if !$WxActivity['WxActivity']['hide_price']}}
							<p><span style="font-size:13px;" class="product-price">{{format_price($item['price'])}}</span></p>
							{{/if}}
							<p><small>{{if $saled_nums[$item['id']]}}已参与<strong>{{$saled_nums[$item['id']]}}</strong>，{{/if}}
								{{if $item['storage']}}
								剩余<strong>{{$item['storage']-$saled_nums[$item['id']]}}</strong></small>
								{{/if}}</p>
						</td>	
						{{if $WxActivity['WxActivity']['status'] == 1}}					
						<td width="32%" align="center">
							{{if $item['storage'] > 0 &&$item['storage']-$saled_nums[$item['id']] <= 0}}
								已报满
							{{else}}
							<?php if($count==1 || $key == 0) {$value=1;}else{$value=0;}   ?>
 							<div class="input-group" style="width:105px;">
							  <span class="reduce input-group-addon" onclick="setAmount.reduce('.pamount-{{$item['id']}}')">-</span>
							  <input class="pamount form-control pamount-{{$item['id']}}" id="pamount-{{$item['id']}}" size="3" value="{{$value}}" class="form-control" name="shoppingnum[{{$item['id']}}]" type="text">
							  <span class="add input-group-addon" onclick="setAmount.add('.pamount-{{$item['id']}}')">+</span>
							</div>
							{{/if}}
						</td>
						{{/if}}
					</tr>
				</portlet>
			</tbody></table>	

		</div>

		<div id="order-list">
			{{if is_array($orders)}}
			{{loop $orders $order}}
				<div class="order-item" data-creator="{{$order['Order']['creator']}}">
					<div class="user-avatar">
						<img src="{{$order['User']['image']}}">
					</div>
					<div class="user-goods">
					<p>{{if $order['Order']['nickname']}}{{$order['Order']['nickname']}}{{else}}{{$order['Order']['consignee_name']}}{{/if}}<small style="margin-left:10px;">({{$order['Order']['created']}})</small></p>
					{{if is_array( $order_carts[$order['Order']['id']] ) }}
					<table class="table  table-noborder">
					{{loop $order_carts[$order['Order']['id']] $cart}}
						<tr><td> {{$cart['name']}} </td><td> {{$cart['num']}}</td></tr>
					{{/loop}}
					</table>
					{{/if}}
					</div>
				</div>
			{{/loop}}
			{{/if}}
		</div>

		{{if $WxActivity['WxActivity']['content']}}
			<div class="ui-portlet-header">
		      <span class="title">报名活动详情</span>            
			</div>

			<div>				
				<div class="wx-text-item noborder">{{$WxActivity['WxActivity']['content']}}</div>
			</div>
		{{/if}}
		
		<p>查看次数: {{$WxActivity['WxActivity']['view_nums']}}</p>
</div>
</div>	

<div id="cart1" class="cart-concern-btm-fixed">
	<div class="concern-cart">
			<a href="/wx_activities/lists?model=Baoming&status=1&creator={{$WxActivity['WxActivity']['creator']}}" class="dong-dong-icn J_ping">
				<i class="fa fa-home"></i>
				<span class="focus-info">首页</span>
			</a>
		<a href="/users/index" class="love-heart-icn J_ping" >
			<i class="fa fa-user"></i>
			<span class="focus-info"> 我的  </span>
		</a>
				
	</div>
	<div class="action-list">
		{{if $WxActivity['WxActivity']['status'] == 1}}
		<a href="javascript:void(0);" class="red-color baoming-btn directorder" onclick="$('#myModal').modal();" id="directorderBtm">
			{{if $WxActivity['WxActivity']['button_name']}}{{$WxActivity['WxActivity']['button_name']}}{{else}}我要报名{{/if}}
		</a>
		{{else}}
		<span style="opacity: 0.5;" class="red-color directorder" disabled="disabled" id="directorderBtm">
			活动已结束
		</span>
		{{/if}} 
	</div>
</div>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-dialog">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">我要报名</h4>
      </div>
      <div class="modal-body">
      	<div class="create-baoming-div">
				<form name="BaomingForm" onsubmit="return submitBaoming(this);" method="post" action="/baomings/addOrder" class="form form-inline form-horizontal" id="BaomingForm">



					{{if $WxActivity['WxActivity']['serialize_info']}}
					<div id="serialize-info" style="margin: 5px 0;">
						{{loop $WxActivity['WxActivity']['serialize_info'] $info}}
							{{if $info['name']}}
							<?php $type = 'text'; if(in_array($info['type'],array('number','email','date'))) { $type = $info['type'];}; ?>
							<p style="margin-bottom:5px;"><label style="width:80px;text-align:right;padding-right:10px;">{{$info['name']}}: </label><input class="form-control serialize_info" type="{{$type}}" required="required" name="data[Order][serialize_info][{{$info['name']}}]" value=""></p>
							{{/if}}
						{{/loop}}
					</div>
					{{/if}}

					<div>
						<p>订单备注：</p>
						<textarea class="form-control" style="width:100%;" rows="2" name="data[Order][remark]"></textarea>
					</div>
					{{if $WxActivity['WxActivity']['allow_pickup']}}
					
					<div class="btn-group" style="margin-top: 5px;margin-left: 0;">
						{{if $WxActivity['WxActivity']['allow_express']}}<label class="btn btn-default active"><input type="radio" checked="checked" class="ship_type" name="data[Order][ship_type]" value="0"> 快递{{if $WxActivity['WxActivity']['ship_fee']}}<small>(费用{{$WxActivity['WxActivity']['ship_fee']}})</small>{{/if}}</label>{{/if}}
						<label class="btn btn-default"><input type="radio" class="ship_type" name="data[Order][ship_type]" value="200"> 自提/现场确认</label>
					</div>
				
					<div id="pickup-addresses" style="border: 1px solid #ddd;padding:10px 15px;">
						{{loop $WxActivity['WxActivity']['pickup_address'] $address}}
							<p><label><input class="pickup_address" type="radio" name="data[Order][pickup_address]" value="{{$address}}">&nbsp;{{$address}}</label></p>
						{{/loop}}
					</div>
					{{/if}}


					{{if $WxActivity['WxActivity']['allow_express']}}
					<input type="hidden" name="data[Order][ship_fee]" value="{{$WxActivity['WxActivity']['ship_fee']}}">
					{{/if}}

					<div>
						{{template orders/order_consignee}}
					</div>

					<div class="row" style="margin-top:8px">
						<input type="hidden" name="source" value="{{$_REQUEST['source']}}">
						<input type="hidden" name="data[Baoming][data_id]" value="{{$id}}">
						<input type="hidden" name="data[Baoming][model]" value="WxActivity">
						<input type="hidden" name="referer" value="/wx_activities/view/{{$id}}">
						<div class="col-xs-6 col-md-6" style="padding-right:8px">
							<input type="submit" id="BaomingSubmit" class="btn btn-primary btn-block"  value="提交"/>
						</div>
						<div class="col-xs-6 col-md-6" style="padding-left:8px">
							<div  data-dismiss="modal" class="btn btn-default btn-block" id="goback">取消</div>
						</div>
					</div>
													 
				</form>
		</div>
      </div>
    </div>
  </div>
</div>
	
<script>

$(function(){



	{{if !$WxActivity['WxActivity']['allow_pickup'] || $WxActivity['WxActivity']['allow_express']}}
    	$('#pickup-addresses').addClass('hidden');
	{{/if}}
    {{if $WxActivity['WxActivity']['allow_pickup'] && !$WxActivity['WxActivity']['allow_express']}}
    $('.ship_type[value=200]').prop('checked',true);
	{{/if}}

	$('.ship_type').click(function(){
		$(this).parents('.btn-group').find('.active').removeClass('active');
		$(this).parents('label').addClass('active');
        if( $('.ship_type:checked').val() == 200 ){
            $('#pickup-addresses').removeClass('hidden');
		}
		else{
            $('#pickup-addresses').addClass('hidden');
            $('.pickup_address:checked').prop('checked',false);
		}
	});

    if($('.pickup_address').size()==1) {
        $('.pickup_address').prop('checked',true);
	}

	
    $('#myModal').on('show.bs.modal', function (e) {
        var table = $('<table class="baoming-choose-table"></table>');
        $('#baoming-items .pamount').each(function(){
            if(this.value > 0 ) {
                $(this).parents('tr:first').clone().appendTo(table);
            }
        });
        if(table.find('tr').size() <= 0) {
            showErrorMessage('请选择对应项目的数目');
            return false;
        }
        $('#BaomingForm').prepend( table );
    })
    $('#myModal').on('hide.bs.modal', function (e) {
        $('.baoming-choose-table').remove();
    });
    
    $('#order-list').prepend( $('.order-item[data-creator={{$current_user_id}}]') );

});

function submitBaoming(form){
	var total = 0;
	$('input.pamount').each(function(){
		total += $(this).val();
	});
	if(total == 0) {
		alert('报名项的数目都为0，无法报名');
	}
    else if( $('.ship_type:checked').val() == 200  && $('.pickup_address:checked').size()==0){
        alert('选择了自提，但没有选中具体的自提点');
    }
	else{
		ajaxSubmitForm(form,function(request){
			if(request.ret ==0 ) {
				if( request.data.total_price > 0 ) {
					window.location = "/orders/pay/"+request.data.id;
				}
				else{
					window.location = "/wx_activities/view/{{$id}}";
				}
				showSuccessMessage(request.msg);
				//window.location.reload();
			}
			else{
				showErrorMessage(request.msg);
			}
		});
	}
	
	return false;
}

</script>